<?php
error_reporting(E_ALL ^ E_NOTICE);
include_once($_SERVER['DOCUMENT_ROOT'] . '/htqlmba/models/m_loaiDau.php');
include_once($_SERVER['DOCUMENT_ROOT'] . '/htqlmba/controls/c_capNhatLoaiDau.php');
?>

<script type="text/javascript">
// funtion lay gia tri tu radio button "chon"
    function getValue(id) {
        document.capnhatloaidau.txtmald.value = document.getElementById("ma_ld" + id).innerHTML;
        document.capnhatloaidau.txttenld.value = document.getElementById("ten_ld" + id).innerHTML;
        document.capnhatloaidau.txttenld_old.value = document.getElementById("ten_ld" + id).innerHTML;

        // chuyen mau cac textfield tendv,diachidv,lienhedv thanh mau trang', va cho phep sua doi thong tin
        document.capnhatloaidau.txtmald.readOnly = true;
        document.capnhatloaidau.txtmald.style.backgroundColor = '#cccccc';
        document.capnhatloaidau.txttenld.style.backgroundColor = '#FFFFFF';

        document.capnhatloaidau.btnsuald.disabled = false;
        document.capnhatloaidau.btnxoald.disabled = false;
        document.capnhatloaidau.btnthemld.disabled = true;

    }

// fuction hien bang xac nhan truoc khi xoa don vi
    function confirmDelete() {
        if (confirm("Bạn có chắc muốn xóa loại dầu này không?")) {
            return true;
        }
        return false;
    }
    function xoadulieu() {
        document.capnhatloaidau.txtmald.readOnly = false;
        document.capnhatloaidau.txttenld.disabled = false;

        document.capnhatloaidau.btnthemld.disabled = false;

        document.capnhatloaidau.txtmald.style.backgroundColor = '#ffffff';
		 document.capnhatloaidau.txtmald.value = "";
        document.capnhatloaidau.txttenld.value = "";
        document.capnhatloaidau.txttenld_old.value = "";
    }



</script>

<!doctype html>
<html>
    <head>
        <meta charset=utf-8 />
        <title>Cập nhật loại dầu</title>
        <link href="/htqlmba/libraries/css/capnhatdv.css" type="text/css" rel="stylesheet">
    </head>

    <body>

        <div class="bodyStyle">
            <form name="capnhatloaidau" method="post" action="">
                <!-- bang hien thi -->  
                <table align="center" class="font" width="500" border="0" cellspacing="0" cellpadding="0">
                    <tr bgcolor="#dae9f3">

                        <td align=center class='TableHeader1'  height="35" > &equiv; Cập nhật loại dầu</td>
                    </tr>
                    <tr bgcolor="#dae9f3">
                        <td colspan="3" valign="top"><table width="793" border="0" align="center" cellpacing='0' cellpadding='0'>
                                <tr>
                                    <td width="79" height="30" class="TableField2">Mã loại dầu</td>
                                    <td align="left" class="error" ><input name="txtmald" type="text" id="txtmald"  size="10" maxlength="100" ><?php echo $maldErr; ?> </td>
                                </tr>
                                <tr>
                                    <td height="37" class="TableField2">Tên loại dầu</td>
                                    <td class="error"><input name="txttenld" type="text" id="txttenld"   size="70" maxlength="50" ><?php echo $tenldErr; ?>
                                        <input name="txttenld_old" type="text" id="txtttmayold"  size="70" maxlength="100"  style="display:none"  >
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2" class="btn_x" id="btn_x" >
                                        <input type="submit" name="btnthemld" id="btnthemld" value="Thêm loại dầu">
                                        <input type="button" name="btnreset" id="btnreset" value="Xóa dử liệu nhập vào" onClick="xoadulieu()">
                                        <input type="submit" name="btnsuald" id="btnsuald" value="Sửa loại dầu" disabled="true">
                                        <input type="submit" name="btnxoald" id="btnxoald" value="Xóa loại dầu"  disabled="true" onClick="confirmDelete()">
                                    </td>
                                </tr>
                            </table></td>
                    </tr>
                </table>
                </br>

                <!-- lay du lieu tu bang don vi va hien thi -->
                <?php
                $loaidau = new LoaiDau();
                $result = $loaidau->dsLD();
                echo "<table align='center' width='600' border='0' cellspacing='0' cellpadding='0' ";
                echo "<tr >";
                echo "<td align='center' class='TableHeader1'> &equiv; Danh sách loại dầu</td>";
                echo "</tr>";
                echo "<tr >";
                echo "<td colspan='3' valign='top'><table width='600' border='0' cellpadding='0' cellspacing='0'>";
                echo "<tr>";
                echo "<td width='30' align='center' class='TableHeader' >STT</td>";
                echo "<td width='120' align='center' class='TableHeader' >Mã loại dầu </td>";
                echo "<td width='400' align='center' class='TableHeader' >Tên loại dầu </td>";
                echo "</tr>";




                $num = mysql_num_rows($result);
                $i = 0;
                echo "<tbody style='display:none;'>";
                while ($row = mysql_fetch_array($result)) {

                    $i++;
                    if ($i % 2 == 0) {
                        echo "</tbody>";
                        echo "<tr onClick='getValue($i);'>";
                        echo "<td align='center' class='TableField2'>" . $i . "</td>";
                        echo "<td  align='center' class='TableField2'><div id='ma_ld$i'>" . $row['MA_LOAI_DAU'] . "</div></td>";
                        echo "<td  align='left' class='TableField2'><div id='ten_ld$i'>" . $row['TEN_LOAI_DAU'] . "</div></td>";
                        echo "</tr>";
                    } else {
                        echo "</tbody>";
                        echo "<tr>";
                        echo "<td align='center' class='TableField'>" . $i . "</td>";
                        echo "<td  align='center' class='TableField'><div id='ma_ld$i'>" . $row['MA_LOAI_DAU'] . "</div></td>";
                        echo "<td  align='left' class='TableField'><div id='ten_ld$i'>" . $row['TEN_LOAI_DAU'] . "</div></td>";
                        
                        echo "</tr>";
                    }
                }
                echo "</tbody>";

                echo "<tr>";
                echo "<td align='left' colspan='9'><span style=' color:#008000'>Tổng số loại dầu: $num";

                echo "</span></td>";
                echo "<td align='right' colspan='2'><font color='green'>";
                echo "</font></td>";
                echo "</tr>";
                echo "</table></td>";
                echo "</tr>";
                echo "</table>";
                //}
//}
                ?>
            </form>
            <!-- het bang -->
        </p>
        <p>&nbsp;
        </p>
    </div>
</body>
</html>
